﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db4objects.Db4o;

namespace WebGetter
{
    class BaseRespository<T> : IRepository<T> where T : IEntity
    {
        protected virtual IObjectContainer GetDb()
        {
            return null;
        }

        public void Save(T entity)
        {
            using (var db = GetDb())
            {
                db.Store(entity);
            }
        }

        public void Remove(object id)
        {
            throw new NotImplementedException();
        }

        public void Remove(T entity)
        {
            throw new NotImplementedException();
        }

        public T Update(T entity)
        {
            throw new NotImplementedException();
        }

        public T GetByID(object id)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<T> QueryBySample(T entity)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<T> GetAll()
        {
            using (var db = GetDb())
            {
                return db.Query<T>().ToList();
            }
        }
    }
}
